﻿using Newtonsoft.Json.Linq;

namespace server
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //初始化一个Http 服务器
            JObject config = null;

            try
            {
                config = JObject.Parse(System.IO.File.ReadAllText("config.json"));
            }
            catch (Exception err)
            {
                Console.WriteLine("config.json 读取错误！！");
            }
            int port = (int)config["port"];
            string firsttag = (string)config["roottag"];
            string dbpath = (string)config["dbpath"];
            dbtool.Init(firsttag, dbpath);
            var http = new light.http.server.httpserver();
            http.SetFailAction(Server.OnFail);
            http.SetHttpAction("/admin_clear", Server.OnAdmin_Clear);
            http.SetHttpAction("/getstatus", Server.OnGetStatus);
            http.SetHttpAction("/tran_calc", Server.OnTran_Calc);
            http.SetHttpAction("/tran_add", Server.OnTran_Add);
            http.SetHttpAction("/tran_gettxid", Server.OnTran_GetTxIDByHeight);
            http.SetHttpAction("/tran_getinfo", Server.OnTran_GetInfo);
            http.SetHttpAction("/tran_getdata", Server.OnTran_GetData);
            http.Start(port);

            while (true)
            {
                try
                {
                    Console.ReadLine();
                }
                catch
                {

                }
            }
   
        }


    }
}